import keymaster from 'keymaster'

// Win 键盘枚举
export enum WinKeyboard {
  CTRL = 'ctrl',
  SHIFT = 'shift',
  ALT = ' alt',
}

// Mac 键盘枚举
export enum MacKeyboard {
  // 还是用 Command 吧
  COMMAND = '⌘',
  SHIFT = '⇧',
  ALT = '⌥',
}

export type Keyboards = string[]

export class HotkeyHelper {
  private _key: string
  private combineKeyboard(keyboards: Keyboards) {
    return keyboards.join('+')
  }
  private unionKey(keys: string[]) {
    return keys.join(', ')
  }
  constructor(keys: Keyboards[], callback: keymaster.KeyHandler) {
    this._key = this.unionKey(keys.map((v) => this.combineKeyboard(v)))
    keymaster(this._key, callback)
  }
  unbind() {
    keymaster.unbind(this._key)
  }
}
